﻿/**
 * ...
 * @author sminutoli
 */

import com.dmotiko.general.*
import com.dmotiko.prune.*
import mx.transitions.easing.Regular;
import mx.transitions.Tween;
import mx.utils.Delegate;
 
class NavBarBack 
extends BaseClip {
	
	public var mcMask:MovieClip;
	public var mcBack:MovieClip;
	
	private function initClip():Void {
		mcBack.setMask( mcMask );
		bShowed = false;
		//mcMask._y = mcBack._y - mcMask._height + 100; 
		mcMask._y = mcBack._y; 
		Site.getApp().addEventListener( WebSite.SECTION_CHANGED, Delegate.create( this, section_changed ) );
	}
	
	private function section_changed(e):Void 
	{
		var nFrame:Number;
		switch( e.section ) {
			case SiteSections.CAMPAIGN:
			nFrame = 2;
			break;
			
			case SiteSections.STORES:
			nFrame = 3;
			break;
			
			case SiteSections.COLLECTION:
			nFrame = 4;
			break;
			
			case SiteSections.FASHION:
			nFrame = 5;
			break;
			
			default:
			nFrame = 1;
			break;
		}
		mcBack.gotoAndStop(nFrame);
		registerTween("backFade", new Tween( mcBack, "_alpha", Regular.easeInOut, 30, 100, 1, true) );
		mcMask._height = mcBack._height;
	}
	
	public function tweenFinished( key:String, tween:Tween ) {
		switch ( key){
			case "moveMask":
			if ( tween.finish == mcBack._y ) { //es el de show
				showEnd();
			} else {
				hideEnd();
			}
			break;
		}
	}
	
	public function show():Void {
		registerTween("moveMask", new Tween( mcBack, "_y", Regular.easeOut, mcBack._y, mcMask._y, 0.5, true), false, true )
	}
	
	public function hide():Void {
		var nEnd:Number;
		switch( Site.getApp().getSection() ) {
			
			case SiteSections.COLLECTION:
			nEnd =  mcMask._y - mcBack._height + 400;
			break;
			
			case SiteSections.CAMPAIGN:
			nEnd =  mcMask._y - mcBack._height + 270;
			break;
			
			case SiteSections.STORES:
			nEnd =  mcMask._y - mcBack._height + 350;
			break;
						
			default:
			nEnd =  mcMask._y - mcBack._height + 120;
			break;
		}
		registerTween("moveMask", new Tween( mcBack, "_y", Regular.easeOut, mcBack._y, nEnd, 0.5, true), false, true )
	}
	
}